#!/bin/bash

ICON="~/.config/i3/scripts/res/volume.png"
ICON_MUTE="~/.config/i3/scripts/res/volume-mute.png"

nocnoc_plus() {
    volume=$(amixer get Master | tail -n1 | sed -r "s/.*\[(.*)%\].*/\1/")
    bar="增加音量，当前音量：$volume %"    
    # [ ${volume[1]} == "on" ] && icon="$ICON" || icon="$ICON_MUTE"
    icon="$ICON"
    dunstify -i $icon -t 1500 -r 2601 -u ctrical "    $bar"
}


nocnoc_minus() {
    volume=$(amixer get Master | tail -n1 | sed -r "s/.*\[(.*)%\].*/\1/")
    bar="减少音量，当前音量：$volume %"   
    #[ ${volume[1]} == "on" ] && icon="$ICON" || icon="$ICON_MUTE"
    icon="$ICON"
    dunstify -i $icon -t 1500 -r 2601 -u ctrical "    $bar"
}

nocnoc_equal() {
    volume=$(amixer get Master | tail -n1 | sed -r "s/.*\[(.*)%\].*/\1/")
    bar="切换静音"   
    #[ ${volume[1]} == "on" ] && icon="$ICON" || icon="$ICON_MUTE"
    icon="$ICON_MUTE"
    dunstify -i $icon -t 1500 -r 2601 -u ctrical "    $bar"
}

case $1 in
    up)
        amixer -qM set Master 5%+ umute
        nocnoc_plus
        ;;
    down)
        amixer -qM set Master 5%- umute
        nocnoc_minus
        ;;
    mute)
        amixer set Master toggle
        nocnoc_equal
        ;;
esac
